package com.action.music;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.music.MusicType;
import com.business.music.MusicTypeBus;
import com.config.SystemGlobals;

public class ManageMusicType extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
	
		if (request.getParameter("deleted") != null) {
			String[] typeIds = request.getParameterValues("deleted");
			MusicTypeBus mtb = new MusicTypeBus();
			for (int i = 0; i < typeIds.length; i++) {
				mtb.del(typeIds[i]);
			}
			out
					.println("<script>alert(\"删除音乐分类成功\");window.location=\"admin/blog/musictypelist.jsp\";</script>");
			out.close();
		}
	if (request.getParameter("edit") != null) {
		String musictypeName = request.getParameter("musictypename");
		String musictypeMemo = request.getParameter("musictypememo");
		String username = request.getParameter("username");
		MusicType lt = new MusicType();
			lt.setMusictypeMemo(musictypeMemo);
			lt.setMusictypeName(musictypeName);
			lt.setUsername(username);
			MusicTypeBus mtb = new MusicTypeBus();
			String typeId = request.getParameter("id");
			mtb.update(lt, typeId);
			out
					.println("<script>alert(\"编辑音乐分类成功\");window.location=\"admin/blog/musictypelist.jsp\";</script>");
			out.close();
		}
	}

}
